from selenium.webdriver.common.by import By

class OperationBrowser:
    def __init__(self,driver):
        self.driver=driver

    def input_text_name(self,type,locator,text):
        if type.lower()=="name":
            self.driver.find_element(By.NAME,locator).send_keys(text)
        elif type.lower()=="id":
            self.driver.find_element(By.ID,locator).send_keys(text)
        elif type.lower()=="xpath":
            self.driver.find_element(By.XPATH,locator).send_keys(text)

    def click_name(self,byte,name):
        if byte=="name":
            self.driver.find_element(By.NAME,name).click()
        elif byte=="xpath":
            self.driver.find_element(By.XPATH, name).click()
    def open_url(self,url):
        self.driver.get(url)

    def change_frame(self,name):
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame(name)


    def get_text_xpath(self,locato):
        return self.driver.find_element(By.XPATH,locato).text

    def change_windows(self, title):
        windows = self.driver.window_handles
        for windows_id in windows:
            self.driver.switch_to.window(windows_id)
            if self.driver.title == title:
                break


    def get_element_XPATH(self,locator):
        return self.driver.find_element(By.XPATH,locator)
    def get_tag_name(self,s,y):
        return s.driver.find_element(By.TAG_NAME,y)






# if __name__=="__main__":
#     ub=UseBrowser("chrome","../chromedriver")
#     ob=OperationBrowser(UseBrowser.driver)
#     ob.open_url("http://localhost:8080/JavaPrj_6/login.do")
#     time.sleep(1)
#     ob.input_text_name("username","admin")
#     time.sleep(1)
#     ob.input_text_name("password", "admin")
#     time.sleep(1)
#     ob.click_name("submit")
#     time.sleep(1)
#     ub.quit()
